<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #menus {
        width: 100px;

        position: relative;
      }
      #menus > div {
        height: 20px;
        background-color: beige;
      }
      #menus > ul {
        list-style: none;
        padding: 0;
        margin: 0;
        position: absolute;
        top: 20px;
        left: 0;
        right: 0;
        background-color: azure;
      }
      #menus > ul li {
        /* border: solid; */
        height: 0px;
        font-size: 0px;
        transition: 200ms;
      }
    </style>
  </head>
  <body>
    <div id="menus">
      <div id="btn">菜单</div>
      <ul id="items">
        <li>添加</li>
        <li>删除</li>
        <li>编辑</li>
      </ul>
    </div>
    <script>
      const btn = document.getElementById("btn");
      const lis = document.querySelectorAll("#items li");
      btn.onclick = function () {
        if (lis[0].style.height) {
          [...lis].forEach((el) => {
            el.style.height = "";
            el.style.fontSize = "";
          });
        } else {
          [...lis].forEach((el) => {
            el.style.height = "20px";
            el.style.fontSize = "14px";
          });
        }
      };
    </script>
  </body>
</html>
